var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "job_number",
			name : "工号"
		},{
			colkey : "name",
			name : "姓名"
		},{
			colkey : "sex",
			name : "性别",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){ return "男"}else{return "女"};
			}
		}, {
			colkey : "dname",
			name : "部门",
			
		},{
			colkey : "poname",
			name : "职务",
			
		},{
			colkey : "phone",
			name : "电话号",
			
		}, {
			colkey : "address",
			name : "住址",
		}, {
			colkey : "IdCard",
			name : "身份证号",
			
		},
		{
			colkey : "first_entry",
			name : "第一次入厂日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "social_security",
			name : "社保",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){ return "已购买"}else{return "没购买"};
			}
		},{
			colkey : "introducer",
			name : "介绍人",
		},{
			colkey : "state",
			name : "状态",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){ return "新员工"}else if(data==2){return "已离职"}else{return "已存档"};
			}
		}],
		jsonUrl : rootPath + '/hrstaff/staffinfomation_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addOrder").click("click", function() {
		addAccount();
	});
	$("#editOrder").click("click", function() {
		editAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	$("#delFuns").click("click", function() {
		delAccounts();
	});
	$("#addOrders").click("click", function() {
		addAccounts();
	});
	$("#addOrdersocal").click("click", function() {
		addAccountsocal();
	});
	$("#addOrdermeal").click("click", function() {
		addmealAccount();
	});
	$("#delFunmeal").click("click", function() {
		demealAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
			
		});
	});
	
});





function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "编辑员工信息 ",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrstaff/staff_edit.shtml?id=' + cbox
	});
}
function addAccount() {
	var cbox = grid.getSelectedCheckbox();
	pageii = layer.open({
		title : "新增员工信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrstaff/staff_add.shtml?id=' + cbox
	});
}
function addAccounts() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "新增档案信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrstaff/record_add.shtml?id=' + cbox
	});
}

function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/hrstaff/staff_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
	
}
/*删除档案*/
function delAccounts() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/hrstaff/record_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
	
}

function addAccountsocal() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择续保项！！");
		return;
	}
	layer.confirm('修改续保？', function(index) {
		var url = rootPath + '/hrstaff/social_addEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('修改成功');
			grid.loadData();
		} else {
			layer.msg('修改失败');
		}
	});
	
}

function addmealAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "新增餐费信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrstaff/meal_add.shtml?id=' + cbox
	});
}
/**
 * 删除餐费信息
 */
function demealAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/hrstaff/meal_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
	
}